/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package it.polimi.games.epkb.entityClasses;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Collection;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author plebani
 */
@Entity
@Table(name = "rule")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Rule.findAll", query = "SELECT r FROM Rule r"),
    @NamedQuery(name = "Rule.findById", query = "SELECT r FROM Rule r WHERE r.id = :id"),
    @NamedQuery(name = "Rule.findByConfidence", query = "SELECT r FROM Rule r WHERE r.confidence = :confidence"),
    @NamedQuery(name = "Rule.findByImportance", query = "SELECT r FROM Rule r WHERE r.importance = :importance")})
public class Rule implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @Column(name = "ID")
    private String id;
    // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
    @Column(name = "Confidence")
    private BigDecimal confidence;
    @Column(name = "Importance")
    private BigDecimal importance;
    @ManyToMany(mappedBy = "ruleCollection")
    private Collection<Predicate> predicateCollection;
    @JoinColumn(name = "Id_Action", referencedColumnName = "ID")
    @ManyToOne
    private Actions idAction;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idRule")
    private Collection<ExecutedRules> executedRulesCollection;

    public Rule() {
    }

    public Rule(String id) {
        this.id = id;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public BigDecimal getConfidence() {
        return confidence;
    }

    public void setConfidence(BigDecimal confidence) {
        this.confidence = confidence;
    }

    public BigDecimal getImportance() {
        return importance;
    }

    public void setImportance(BigDecimal importance) {
        this.importance = importance;
    }

    @XmlTransient
    public Collection<Predicate> getPredicateCollection() {
        return predicateCollection;
    }

    public void setPredicateCollection(Collection<Predicate> predicateCollection) {
        this.predicateCollection = predicateCollection;
    }

    public Actions getIdAction() {
        return idAction;
    }

    public void setIdAction(Actions idAction) {
        this.idAction = idAction;
    }

    @XmlTransient
    public Collection<ExecutedRules> getExecutedRulesCollection() {
        return executedRulesCollection;
    }

    public void setExecutedRulesCollection(Collection<ExecutedRules> executedRulesCollection) {
        this.executedRulesCollection = executedRulesCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Rule)) {
            return false;
        }
        Rule other = (Rule) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "it.polimi.games.epkb.entityClasses.Rule[ id=" + id + " ]";
    }
    
}
